#include "../StdInc.h"

#ifndef _RUN_COMMANDLINE_MODE

#include <fstream>

#include "msgpack.hpp"


namespace GSTrader
{
	namespace QuoteService
	{
		CRealQuoteManager::CRealQuoteManager(PVOID lpDataManager) : m_pDataManager(lpDataManager)
		{
			this->LoadOpenCloseConfigFile();
			this->LoadMarketData();
		}

		CRealQuoteManager::~CRealQuoteManager()
		{
			this->SaveMarketData();
		}

		bool CRealQuoteManager::LoadOpenCloseConfigFile()
		{
			return true;
		}

		void CRealQuoteManager::LoadMarketData()
		{

		}

		void CRealQuoteManager::SaveMarketData()
		{

		}

		COpenCloseTime* CRealQuoteManager::GetOpenCloseTimeByType(string strType)
		{
			return NULL;
		}

		COpenCloseTime* CRealQuoteManager::GetOpenCloseTimeBySymbol(string strInstrumentId)
		{
			return NULL;
		}

		string CRealQuoteManager::GetExchageIdBySymbol(string strInstrumentId)
		{
			return "";
		}

		void CRealQuoteManager::OnMarketData(CDepthMarketData* pMarketData)
		{
			
		}

		bool CRealQuoteManager::GetMin1FromRealData(string strCode, vector<SHistoricalData>& vHisData)
		{
			return false;
		}

		bool CRealQuoteManager::GetHistoricalData(CBarSeriesIndex& BarSeriesIndex, vector<SHistoricalData>& vHisData)
		{
			return false;
		}

		bool CRealQuoteManager::GetTickData(string strCode, vector<SGSTickData>& vTickData)
		{
			return false;
		}

		bool CRealQuoteManager::UpdateTickData(string strExchangeId, string strCode, vector<SGSTickData>& vTickData)
		{
			return false;
		}

		void CRealQuoteManager::OnInstrument(CMsg* pMsg)
		{
	
		}

		CDepthMarketData* CRealQuoteManager::GetMarketDataById(int nInstrumentId)
		{
			if (nInstrumentId < 0)
			{
				return nullptr;
			}

			CDepthMarketData* pDepthMarketData = ((CDataManager*)m_pDataManager)->m_pDataBase->GetMarketDataById(nInstrumentId);
			if (pDepthMarketData == nullptr)
			{
				CInstrument* pInstrument = ((CDataManager*)m_pDataManager)->m_pDataBase->GetInstrumentById(nInstrumentId);
				if (pInstrument)
				{
					CDepthMarketData newData(*pInstrument);
					pDepthMarketData = ((CDataManager*)m_pDataManager)->m_pDataBase->UpdateDepthMarketData(&newData);
				}
			}

			return pDepthMarketData;
		}

		CDepthMarketData* CRealQuoteManager::GetMarketDataBySymbol(CInstrumentLongCode& code)
		{
			CDepthMarketData* pDepthMarketData = ((CDataManager*)m_pDataManager)->m_pDataBase->GetMarketDataBySymbol(code);
			if (pDepthMarketData == NULL)
			{
				CInstrument* pInstrument = ((CDataManager*)m_pDataManager)->m_pDataBase->GetInstrumentBySymbol(code.m_strInstrumentId, code.m_strExchangeId);
				if (pInstrument)
				{
					CDepthMarketData newData(*pInstrument);
					pDepthMarketData = ((CDataManager*)m_pDataManager)->m_pDataBase->UpdateDepthMarketData(&newData);
				}
			}

			return pDepthMarketData;
		}

		CDepthMarketData* CRealQuoteManager::GetMarketDataBySymbol(string strInstrumentId, string strExchangeId)
		{
			return GetMarketDataBySymbol(CInstrumentLongCode(strInstrumentId, strExchangeId));
		}
	}
}

#endif